package com.example.generator.controller;

import com.example.generator.dto.UserDetailResponse;
import com.example.generator.model.User;
import com.example.generator.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/test")
    public String test()
    {
        return "test";
    }

    @RequestMapping("detail/{id}")
    public Object detail(@PathVariable("id") Long id)
    {
        User user = userService.getUserById(id);

        // 使用自定义的结果返回结构
        UserDetailResponse detail = new UserDetailResponse();

        detail.setId(user.getId());
        detail.setUsername(user.getUsername());
        detail.setEmail(user.getEmail());

        return detail;
    }
}
